/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package py.com.sole.model;

import java.io.Serializable;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author bala
 */
@Entity
@Table(name = "padres")
@XmlRootElement
@NamedQueries({
  @NamedQuery(name = "Padre.findAll", query = "SELECT p FROM Padre p WHERE p.activo=TRUE"),
  @NamedQuery(name = "Padre.findById", query = "SELECT p FROM Padre p WHERE p.id = :id and p.activo=TRUE"),
  @NamedQuery(name = "Padre.findPadrePersona", query = "SELECT p.id, per.nombre, per.apellido, per.documento, per.telefono, per.email FROM Padre p LEFT JOIN p.persona per WHERE p.activo=TRUE")})

public class Padre implements Serializable {

  private static final long serialVersionUID = 1L;
  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  @Basic(optional = false)
  @Column(nullable = false)
  private Integer id;
  @ManyToMany(mappedBy = "padreList")
  private List<Alumno> alumnoList;
  @JoinColumn(name = "persona", referencedColumnName = "id", nullable = false)
  @ManyToOne(optional = false, cascade = CascadeType.ALL)
  private Persona persona;
  private Boolean activo;

  public Padre() {
  }

  public Padre(Integer id) {
    this.id = id;
  }

  public Integer getId() {
    return id;
  }

  public void setId(Integer id) {
    this.id = id;
  }

  @XmlTransient
  public List<Alumno> getAlumnoList() {
    return alumnoList;
  }

  public void setAlumnoList(List<Alumno> alumnoList) {
    this.alumnoList = alumnoList;
  }

  public Persona getPersona() {
    return persona;
  }

  public void setPersona(Persona persona) {
    this.persona = persona;
  }

  public Boolean isActivo() {
    return activo;
  }

  public void setActivo(Boolean activo) {
    this.activo = activo;
  }

  @Override
  public int hashCode() {
    int hash = 0;
    hash += (id != null ? id.hashCode() : 0);
    return hash;
  }

  @Override
  public boolean equals(Object object) {
    // TODO: Warning - this method won't work in the case the id fields are not set
    if (!(object instanceof Padre)) {
      return false;
    }
    Padre other = (Padre) object;
    if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
      return false;
    }
    return true;
  }

  @Override
  public String toString() {
    return "py.com.sole.model.Padre[ id=" + id + " ]";
  }
}
